import java.time.LocalDateTime;

public abstract class User {
    private String userId;
    private String username;
    private String password; // 存储MD5加密后的密码
    private LocalDateTime registerTime;
    private UserType userType;
    private String phone;

    public User(String userId, String username, String password, UserType userType, String phone) {
        this.userId = userId;
        this.username = username;
        this.password = MD5Util.encrypt(password); // 密码加密存储
        this.registerTime = LocalDateTime.now();
        this.userType = userType;
        this.phone = phone;
    }

    // 验证密码（输入明文，加密后比对）
    public boolean verifyPassword(String inputPassword) {
        return this.password.equals(MD5Util.encrypt(inputPassword));
    }

    // 修改密码
    public boolean changePassword(String oldPwd, String newPwd) {
        if (verifyPassword(oldPwd)) {
            this.password = MD5Util.encrypt(newPwd);
            return true;
        }
        return false;
    }

    // 抽象方法：显示角色对应的菜单
    public abstract void showMenu();

    // getter和setter
    public String getUserId() {
        return userId;
    }

    public String getUsername() {
        return username;
    }

    public String getPassword() {
        return password;
    }

    public LocalDateTime getRegisterTime() {
        return registerTime;
    }

    public UserType getUserType() {
        return userType;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
}
    